﻿using markdown_picture_packer.common.constants;
using markdown_picture_packer.common.enums;
using markdown_picture_packer.common.utils;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace markdown_picture_packer.frontend.panels
{
    public class FilePathPanel : BasePanel
    {
        private Label Lb;
        private CheckBox Cb;
        private SelectPathPanel Spp;
        public override void InitComponent()
        {
            Lb = new Label { Text = "文件路径:", Font = Constants.MAIN_FONT, ForeColor = Color.Blue, TextAlign = ContentAlignment.MiddleCenter };
            Cb = new CheckBox { Text = "批量", Font = Constants.MAIN_FONT, };
            Spp = new SelectPathPanel(SelectPathType.FILE);
        }
        public override void InitSize(int newWdith, int newHeight)
        {
            Lb.Size = new Size(93, newHeight);
            Cb.Size = new Size(69, newHeight);
            Spp.Size = new Size(FrontUtil.GetFillWidth(newWdith, Lb, Cb), newHeight);
        }
        public override void InitLocation()
        {
            Lb.Location = new Point(0, 0);
            FrontUtil.OnRight(Cb, Lb, 0);
            FrontUtil.OnRight(Spp, Cb, 0);
        }
        public override void InitEvent()
        {
            base.InitEvent();
            Cb.CheckedChanged += (s, e) => Spp.BindEvent(Cb.Checked ? SelectPathType.DIRECTORY : SelectPathType.FILE);
        }
        public override void AddComponent()
        {
            Controls.Add(Lb);
            Controls.Add(Cb);
            Controls.Add(Spp);
        }
        public string GetPath()
        {
            string path = Spp.GetVal();
            if (string.IsNullOrEmpty(path)) return null;
            return (Cb.Checked ? Directory.Exists(path) : File.Exists(path)) ? path : null;
        }
        public bool IsChecked()
        {
            return Cb.Checked;
        }
    }
}
